package com.itheia.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration  // 声明配置类
public class WebConfig implements WebMvcConfigurer {

    // 配置放行
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        System.out.println("页面放行已完成~~~");

        registry.addResourceHandler("/info/css/**")
                .addResourceLocations("classpath:/info/css/");

        registry.addResourceHandler("/info/js/**")
                .addResourceLocations("classpath:/info/js/");

        registry.addResourceHandler("/info/pages/**")
                .addResourceLocations("classpath:/info/pages/");

        registry.addResourceHandler("/info/plugins/**")
                .addResourceLocations("classpath:/info/plugins/");

    }


    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        // 自定义的映射转化覆盖掉 原来的json 消息转化
        converter.setObjectMapper(new JacksonObjectMapper());

        // 让新的消息转换器生效  把消息转换器对象添加进消息转换器的集合中 0索引是最高级别的优先级 生效顺序
        converters.add(0, converter);
    }

}
